//
//  YXThemeManager.m
//  YXTheme_Example
//
//  Created by GMS on 2020/8/18.
//  Copyright © 2020 Arthur. All rights reserved.
//

#import "YXThemeManager.h"
#import "UIColor+YXThemeColor.h"

@interface YXThemeManager ()

/// 当前主题色
@property (nonatomic,strong) NSDictionary *currentColorsDic;

/// 所有的颜色
@property (nonatomic,strong) NSDictionary *colorsMap;

@end

@implementation YXThemeManager

// MARK: 创建单例
+ (YXThemeManager *)shareInstance {
    
    static YXThemeManager *_instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[YXThemeManager alloc] init];
        
        NSString *mapPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"YXTheme" ofType:@"plist"];
        if (!mapPath) {
            return;
        }
        _instance.colorsMap = [NSDictionary dictionaryWithContentsOfFile:mapPath];
    });
    return  _instance;
}

// MARK: 改变主题
- (void)chanageThemeWithType:(YXThemeType)type {
    
    self.themeType = type;
    
    [[NSNotificationCenter defaultCenter] postNotificationName:YXThemeChangedNotification object:nil];
}

// MARK: 根据名字获取颜色
+ (UIColor *)colorWithColorName:(NSString *)colorName {
    
    NSLog(@"self.currentColorsDic *** %@",YXThemeManagerShare.currentColorsDic);
    
    NSString *color = YXThemeManagerShare.currentColorsDic[colorName];
    return [UIColor yx_colorWithHexString:color andAlpha:1];
    
}

// MARK: 根据名字和透明度获取颜色
+ (UIColor *)colorWithColorName:(NSString *)colorName andAlpha:(CGFloat)alpha {
    NSString *color = YXThemeManagerShare.currentColorsDic[colorName];
    return [UIColor yx_colorWithHexString:color andAlpha:alpha];
}

// MARK: 设置主题类型
- (void)setThemeType:(YXThemeType)themeType {
    _themeType = themeType;
    _currentColorsDic = (themeType == YXThemeTypeBlack)?_colorsMap[@"black"]:_colorsMap[@"white"];
}











@end
